package org.glut.cloud.repairManage.controller;

import org.glut.cloud.repairManage.dto.FailureRepair;
import org.glut.cloud.repairManage.entity.RepairTasks;
import org.glut.cloud.repairManage.feign.FailureRepairService;
import org.glut.cloud.repairManage.service.IRepairTasksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * 维修进度表 前端控制器
 *
 * @author linghuhuolian
 * @since 2024-08-13 15:47
 */
@RestController
@RequestMapping("/repair-tasks")
public class RepairTasksController {

    @Autowired
    private IRepairTasksService irepairTasksService;

    // 注入 feign 客户端
    @Autowired
    private FailureRepairService failureRepairService;

    @Autowired
    private RestTemplate restTemplate;

    /**
     * 查询维修人员的所有任务
     */
    @GetMapping("/selectAll/{repairPersonnelId}/{status}")
    public List<RepairTasks> selectAll(@PathVariable Integer repairPersonnelId,
                                       @PathVariable String status) {

        List<RepairTasks> list= irepairTasksService.selectAll(repairPersonnelId, status);
        return list;
    }

    /**
     * 根据故障报修ID查询相应报修的故障信息 远程
     * */
    @GetMapping("/selectById/{failureRepairId}")
    public FailureRepair selectById(@PathVariable Integer failureRepairId) {
        ResponseEntity<FailureRepair> entity = restTemplate.getForEntity("http://repair-RepairManage/failure-repair/selectById",
                FailureRepair.class,
                failureRepairId);
        return entity.getBody();
    }

    /**
     * 接受任务，将repair_task表中的任务状态参数（status）值改为'正在处理',并将接受任务的时间赋值给acceptance_time属性
     * */
    @PutMapping("/acceptTask/{taskId}")
    public boolean acceptTask(@PathVariable Integer taskId) {
        return irepairTasksService.acceptTask(taskId);
    }
}
